package xyz.ddlnt.servicemq.listener;

import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;
import xyz.ddlnt.servicemq.service.UserService;

/**
 * @author ZZULI_SE 210910
 * @data 2025/5/9 19:11
 */
@Slf4j
@Component
public class UserListener {
    @Resource
    private UserService userService;

    /**
     * 用户文章数加1
     * @param userId
     */
    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(name = "post_plus_one"),
            exchange = @Exchange(name =  "usr.user"),
            key = "post_plus_one"
    ))
    public void postPlusOne(Long userId) {
        userService.postPlusOne(userId);
        log.info("用户文章数加1");
    }

    /**
     * 用户文章数减1
     * @param userId
     */
    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(name = "post_minus_one"),
            exchange = @Exchange(name =  "usr.user"),
            key = "post_minus_one"
    ))
    public void postMinusOne(Long userId) {
        userService.postMinusOne(userId);
        log.info("用户文章数减1");
    }

    /**
     * 用户关注数加1
     * @param userId
     */
    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(name = "follow_plus_one"),
            exchange = @Exchange(name =  "usr.user"),
            key = "follow_plus_one"
    ))
    public void followPlusOne(Long userId) {
        userService.followPlusOne(userId);
        log.info("用户关注数加1");
    }

    /**
     * 用户关注数减1
     * @param userId
     */
    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(name = "follow_minus_one"),
            exchange = @Exchange(name =  "usr.user"),
            key = "follow_minus_one"
    ))
    public void followMinusOne(Long userId) {
        userService.followMinusOne(userId);
        log.info("用户关注数减1");
    }

    /**
     * 用户粉丝数加1
     * @param userId
     */
    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(name = "fans_plus_one"),
            exchange = @Exchange(name =  "usr.user"),
            key = "fans_plus_one"
    ))
    public void fansPlusOne(Long userId) {
        userService.fansPlusOne(userId);
        log.info("用户粉丝数加1");
    }

    /**
     * 用户粉丝数减1
     * @param userId
     */
    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(name = "fans_minus_one"),
            exchange = @Exchange(name =  "usr.user"),
            key = "fans_minus_one"
    ))
    public void fansMinusOne(Long userId) {
        userService.fansMinusOne(userId);
        log.info("用户粉丝数减1");
    }

    /**
     * 用户被收藏数加1
     * @param userId
     */
    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(name = "collected_count_plus_one"),
            exchange = @Exchange(name =  "usr.user"),
            key = "collected_count_plus_one"
    ))
    public void collectedCountPlusOne(Long userId) {
        userService.collectedCountPlusOne(userId);
        log.info("用户被收藏数加1");
    }

    /**
     * 用户被收藏数减1
     * @param userId
     */
    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(name = "collected_count_minus_one"),
            exchange = @Exchange(name =  "usr.user"),
            key = "collected_count_minus_one"
    ))
    public void collectedCountMinusOne(Long userId) {
        userService.collectedCountMinusOne(userId);
        log.info("用户被收藏数减1");
    }
}
